import logging

from config import BASE_HOST


class RegLoginApi:

    def __init__(self,ses):
        self.ses=ses


    #获取图片验证码
    def get_img_verify_code(self,r): # 0.1426580900762553
        url= BASE_HOST + f"/common/public/verifycode1/{r}"
        resp=self.ses.get(url=url)

        return resp
    #获取短信 验证码
    def get_phone_verify_code(self,phone,imgcode,type="reg"):
        url = BASE_HOST + "/member/public/sendSms"
        form_dict={"phone": phone, "imgVerifyCode": imgcode, "type": type}
        resp=self.ses.post(url=url,data=form_dict)
        logging.info(f"获取短信验证码响应数据为{resp.json()}")

        return resp

    def user_register(self,form_data):
        url = BASE_HOST + "/member/public/reg"
        form_dict = form_data
        resp = self.ses.post(url=url, data=form_dict)
        logging.info(f"注册响应数据为{resp.json()}")
        return resp

    def user_login(self,username,password):
        url = BASE_HOST + "/member/public/login"
        form_dict = {"keywords":username,"password":password}
        resp = self.ses.post(url=url, data=form_dict)
        logging.info(f"登录响应数据为{resp.json()}")
        return resp
